﻿using System;

namespace Basmus.Web.Topology
{
    public static class TopologyHelper
    {
        public static IApplication Add<TTarget>(this IApplication application)
        {
            application.Add(typeof (TTarget));
            return application;
        }
        public static IApplication Remove<TTarget>(this IApplication application)
        {
            application.Remove(typeof (TTarget));
            return application;
        }
        public static IDomain Add(this IDomain domain, string appVirtualPath, bool routeExistingFiles)
        {
            var appDeclaration = new Application(domain, appVirtualPath);
            domain.Add(appDeclaration);
            return domain;
        }
        public static IDomain Add(this IDomain domain, string appVirtualPath, bool routeExistingFiles, Action<IApplication> config)
        {
            var appDeclaration = new Application(domain, appVirtualPath);
            domain.Add(appDeclaration);
            config(appDeclaration);
            return domain;
        }

        public static ITopology Add(this ITopology topology, string domain)
        {
            var domainDeclaration = new Domain(topology, domain);
            topology.Add(domainDeclaration);
            return topology;
        }

        public static ITopology Add(this ITopology topology, string domain, Action<IDomain> config)
        {
            var domainDeclaration = new Domain(topology, domain);
            topology.Add(domainDeclaration);
            config(domainDeclaration);
            return topology;
        }

        public static ITopology CreateTopology()
        {
            return new Topology();
        }
    }
}